﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Common;
using System.Web.SessionState;
using System.Dynamic;
using Model;
using DAL;
using System.Data;
using System.Dynamic;
using System.Net;
using System.Text;
using System.Web.SessionState;
using JPushAPI;
using System.Security.Cryptography;

namespace UI.tools
{
    /// <summary>
    /// Admin 的摘要说明
    /// </summary>
    public class Admin : IHttpHandler, IRequiresSessionState
    {
        static Dictionary<string, Func<int, string>> hs = new Dictionary<string, Func<int, string>>();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = JobRequest.GetRequestString("act");
            string result = string.Empty;
            if (Commons.CheckSign())
            {
                int adminid = 0;
                if (B.MyAdmin != null)
                {
                    adminid=B.MyAdmin.ID;
                }
                result = hs[action](adminid);
            }
            else
            {
                result = Commons.GetFaild("身份验证失败");
            }
            context.Response.Write(result);
            context.Response.End();
        }
        static Admin()
        {
            /*后台登陆*/
            #region 获取管理员列表
            hs.Add("Find_Admin", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<AdminInfo> list = AdminDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                foreach (AdminInfo info in list)
                {
                    info.UserPwd = DESEncrypt.Decrypt(info.UserPwd);
                }
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存管理员
            hs.Add("Save_Admin", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string realname = JobRequest.GetRequestString("realname"); //真是姓名
                string userpwd = DESEncrypt.Encrypt(JobRequest.GetRequestString("userpwd")); //密码
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = id,
                    UserName = username,
                    UserPwd = userpwd,
                    RealName = realname,
                    CreateDate = DateTime.Now,
                };
                if (id == 0)
                {
                    ID = AdminDAL.Save(info);
                    TagsDAL.Save(new TagsInfo() { AdminID = ID, Name = "新品上市", Count = 4, Sort = 1});
                    TagsDAL.Save(new TagsInfo() { AdminID = ID, Name = "热门推荐", Count = 4, Sort = 2});
                    AdDAL.Save(new AdInfo() { ID = id, AdminID = adminid, SID = 0, Name = "广告1", Img = "/img/banner1.png", Link = "", Position = 1, Sort = 1, Froms = 1, Context = "", CreateDate = DateTime.Now });
                    AdDAL.Save(new AdInfo() { ID = id, AdminID = adminid, SID = 0, Name = "广告2", Img = "/img/banner2.png", Link = "", Position = 1, Sort = 1, Froms = 1, Context = "", CreateDate = DateTime.Now });
                    AdDAL.Save(new AdInfo() { ID = id, AdminID = adminid, SID = 0, Name = "广告3", Img = "/img/banner3.png", Link = "", Position = 1, Sort = 1, Froms = 1, Context = "", CreateDate = DateTime.Now });
                    int parentid= CategoryDAL.Save(new CategoryInfo(){AdminID = adminid,ParentID = 0,Name = "大分类",Sort = 1,Img = "/img/cate.png",});
                    CategoryDAL.Save(new CategoryInfo() {AdminID = adminid, ParentID = parentid, Name = "小分类", Sort = 1, Img = "/img/cate.png", });
                }
                else
                {
                    ID = AdminDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 后台登陆
            hs.Add("Login", (int adminid) =>
            {
                //参数
                try
                {
                    string username = JobRequest.GetRequestString("username"); //用户名
                    string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                    bool rememberme = JobRequest.GetRequestBool("rememberme"); //是否记住密码
                    int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                    //参数
                    AdminInfo info = AdminDAL.Login(username, DESEncrypt.Encrypt(userpwd));
                    if (info.ID > 0)
                    {
                        if (source == 1 || source == 0)
                        {
                            B.MyAdmin = info;
                        }
                        if (rememberme)
                        {
                            CookieHelper.WriteCookie("admin_username", username, 43200);
                            CookieHelper.WriteCookie("admin_userpwd", userpwd, 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "true", 43200);
                        }
                        else
                        {
                            CookieHelper.WriteCookie("admin_username", "", 43200);
                            CookieHelper.WriteCookie("admin_userpwd", "", 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "false", 43200);
                        }
                        
                        return Commons.GetSuccess("登陆成功", info);
                    }
                    else
                    {
                        return Commons.GetFaild("用户名或密码错误");
                    }
                }
                catch (Exception ex)
                {
                    return Commons.GetFaild(ex.Message);
                }
            });
            #endregion
            #region 修改密码
            hs.Add("Update_Pwd", (int adminid) =>
            {
                //参数
                int userid = JobRequest.GetRequestInt("userid"); //用户ID
                string oldpwd = JobRequest.GetRequestString("oldpwd"); //旧密码
                string newpwd = JobRequest.GetRequestString("newpwd"); //新密码
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                AdminInfo user = new AdminInfo();
                if (source == 1 || source == 0)
                {
                    user = B.MyAdmin;
                }
                else
                {
                    user = AdminDAL.FindOneByID(userid);
                }

                if (user.UserPwd != oldpwd)
                {
                    return Commons.GetFaild("旧密码错误");
                }
                bool ok = CommonDAL.UpdateColumnByID(user.ID, "userpwd", DESEncrypt.Encrypt(newpwd), "[admin]");
                if (ok)
                {
                    if (source == 1 || source == 0)
                    {
                        B.MyAdmin.UserPwd = newpwd;
                    }
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 删除管理员
            hs.Add("Delete_Admin", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 设置权限
            hs.Add("Power_Admin", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //用户ID
                string power = JobRequest.GetRequestString("power"); //权限，用户id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.UpdateColumnByID(id, "Power", power, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("设置成功", "");
                }
                else
                {
                    return Commons.GetFaild("设置失败");
                }
            });
            #endregion

            /*用户*/
            #region 获取用户列表
            hs.Add("Find_User", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<UserInfo> list = UserDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion           
            #region 保存用户
            hs.Add("Save_User", (int adminid) =>
            {

                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                string realname = JobRequest.GetRequestString("realname"); //真实姓名
                string sex = JobRequest.GetRequestString("sex"); //性别
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                UserInfo info = new UserInfo()
                {
                    ID = id,
                    UserName=username,
                    UserPwd = DESEncrypt.Encrypt(userpwd),
                    RealName=realname,
                    Sex = sex,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = UserDAL.Save(info);
                }
                else
                {

                    ID = UserDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除用户
            hs.Add("Delete_User", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[user]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 导出用户
            hs.Add("Export_User", (int adminid) =>
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("姓名");
                dt.Columns.Add("手机号");
                List<UserInfo> list = UserDAL.FindAll();
                foreach (UserInfo info in list)
                {
                    DataRow dr = dt.NewRow();
                    dr["姓名"] = info.RealName;
                    dr["手机号"] = info.Mobile;
                    dt.Rows.Add(dr);
                }
                Common.ExcelHelper.DataTableToExcel(dt, "用户手机号-" + DateTime.Now.ToString("yyyy-MM-dd"));
                return Commons.GetSuccess("导出成功", "");
            });
            #endregion


            /*客服*/
            #region 获取客服
            hs.Add("Find_Kf", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<KfInfo> list = KfDAL.FindPage(keyword, adminid, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存客服
            hs.Add("Save_Kf", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //客服姓名
                string mobile = JobRequest.GetRequestString("mobile"); //客服电话
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                KfInfo info = new KfInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Mobile = mobile,
                    Name = name
                };
                if (id == 0)
                {
                    ID = KfDAL.Save(info);
                }
                else
                {

                    ID = KfDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除客服
            hs.Add("Delete_Kf", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[kf]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*广告*/
            #region 获取广告
            hs.Add("Find_Ad", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<AdInfo> list = AdDAL.FindPage(keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存广告
            hs.Add("Save_Ad", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int sid = JobRequest.GetRequestInt("sid"); //资讯ID
                string name = JobRequest.GetRequestString("name"); //名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string link = JobRequest.GetRequestString("link"); //链接
                int position = JobRequest.GetRequestInt("position"); //位置
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int froms = JobRequest.GetRequestInt("froms"); //文章来源   1.自定义内容  2.从文章中选
                string context = JobRequest.GetRequestString("context"); //内容
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdInfo info = new AdInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    SID = sid,
                    Name = name,
                    Img = img,
                    Link = link,
                    Position = position,
                    Sort = sort,
                    Froms = froms,
                    Context = context,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = AdDAL.Save(info);
                }
                else
                {

                    ID = AdDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除广告
            hs.Add("Delete_Ad", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[ad]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*分类*/
            #region 获取分类
            hs.Add("Find_Category", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<CategoryInfo> alllist = CategoryDAL.FindAll(adminid);
                List<CategoryInfo> parentlist = alllist.Where(x => x.ParentID == 0).ToList();
                List<CategoryInfo> list = new List<CategoryInfo>();
                foreach (CategoryInfo menu in parentlist)
                {
                    list.Add(menu);
                    list.AddRange(alllist.Where(x => x.ParentID == menu.ID));
                }
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存分类
            hs.Add("Save_Category", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //分类名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                CategoryInfo info = new CategoryInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    ParentID = parentid,
                    Name = name,
                    Sort = sort,
                    Img = img != "" ? img : "/img/cate.png",
                };
                if (id == 0)
                {
                    ID = CategoryDAL.Save(info);
                }
                else
                {
                    ID = CategoryDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除分类
            hs.Add("Delete_Category", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[category]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*资讯*/
            #region 获取资讯
            hs.Add("Find_News", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                int newstypeid = JobRequest.GetRequestInt("newstypeid"); //1.商城公告  2.系统通知
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<NewsInfo> list = NewsDAL.FindPage(newstypeid, keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存资讯
            hs.Add("Save_News", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //
                int newstypeid = JobRequest.GetRequestInt("newstypeid"); //
                string title = JobRequest.GetRequestString("title"); //标题
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string context = JobRequest.GetRequestString("context"); //内容
                int clickcount = JobRequest.GetRequestInt("clickcount"); //点击量
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                NewsInfo info = new NewsInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    NewsTypeID = newstypeid,
                    Title = title,
                    Img = img!=""?img:"/img/zixun.gif",
                    Context = context,
                    ClickCount = clickcount,
                    Sort = sort,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = NewsDAL.Save(info);
                }
                else
                {
                    ID = NewsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除资讯
            hs.Add("Delete_News", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[news]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*产品*/
            #region 获取产品
            hs.Add("Find_Product", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<ProductInfo> list = ProductDAL.FindPage(0,0,-1,"",keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                foreach (ProductInfo info in list)
                {
                    info.Context = Commons.SubString(Commons.FilterHTML(info.Context),50);
                }
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存产品
            hs.Add("Save_Product", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int category1id = JobRequest.GetRequestInt("category1id"); //1级类别ID
                int category2id = JobRequest.GetRequestInt("category2id"); //2级类别ID
                string num = JobRequest.GetRequestString("num"); //产品编号
                string name = JobRequest.GetRequestString("name"); //产品名称
                string img = JobRequest.GetRequestString("img"); //产品图片
                float oprice = JobRequest.GetRequestFloat("oprice"); //原价
                float aprice = JobRequest.GetRequestFloat("aprice"); //现价
                float pprice = JobRequest.GetRequestFloat("pprice"); //拼团价格
                string unit = JobRequest.GetRequestString("unit"); //单位
                int sellcount = JobRequest.GetRequestInt("sellcount"); //销量
                int allsellcount = JobRequest.GetRequestInt("allsellcount"); //总销量
                int librarycount = JobRequest.GetRequestInt("librarycount"); //库存数量
                string tags = JobRequest.GetRequestString("tags"); //产品标签
                string context = JobRequest.GetRequestString("context"); //产品详情
                int clickcount = JobRequest.GetRequestInt("clickcount"); //点击量
                int sort = JobRequest.GetRequestInt("sort"); //排序
                float allrank = JobRequest.GetRequestFloat("allrank"); //综合排名
                int updown = JobRequest.GetRequestInt("updown"); //上架下架 0.下架 1上架
                float expressmoney = JobRequest.GetRequestFloat("expressmoney"); //快递费用
                int pricetype = JobRequest.GetRequestInt("pricetype"); //价格类型：1.单价格   2.多价格
                string pricename = JobRequest.GetRequestString("pricename"); //多价格标题
                int ispin = JobRequest.GetRequestInt("ispin"); //是否加入拼团
                string format1 = JobRequest.GetRequestString("format1"); //参数1
                string format2 = JobRequest.GetRequestString("format2"); //参数2
                string format3 = JobRequest.GetRequestString("format3"); //参数3
                string format4 = JobRequest.GetRequestString("format4"); //参数4
                string format5 = JobRequest.GetRequestString("format5"); //参数5
                string prices = JobRequest.GetRequestString("prices"); //多个价格
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                string[] pricess = prices.Split(',');
                if (pricetype == 2)
                {
                    int count = 0;
                    librarycount = 0;
                    foreach (string price in pricess)
                    {
                        count++;
                        string[] pp = price.Split('&');
                        //把第一个价格取出来，作为基本价格
                        if (count == 1)
                        {
                            unit = pp[0];
                            oprice = DataConvert.ToFloat(pp[1]);
                            aprice = DataConvert.ToFloat(pp[2]);
                        }
                        librarycount+=DataConvert.ToInt(pp[3]);
                    }
                }
                ProductInfo info = new ProductInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Category1ID = category1id,
                    Category2ID = category2id,
                    Num = num,
                    Name = name,
                    Img = img.Replace(Commons.domain,""),
                    OPrice = oprice,
                    APrice = aprice,
                    PPrice = pprice,
                    Unit = unit,
                    SellCount = sellcount,
                    AllSellCount = allsellcount,
                    LibraryCount = librarycount,
                    Tags = tags,
                    Context = context,
                    ClickCount = clickcount,
                    Sort = sort,
                    AllRank = allrank,
                    UpDown = updown,
                    ExpressMoney = expressmoney,
                    PriceType = pricetype,
                    PriceName = pricename,
                    IsPin = 0,
                    Format1 = format1,
                    Format2 = format2,
                    Format3 = format3,
                    Format4 = format4,
                    Format5 = format5,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = ProductDAL.Save(info);
                    ProductParamDAL.UpdateProductID(adminid, ID);
                }
                else
                {
                    ID = ProductDAL.Update(info);
                }
                if (ID > 0)
                {
                    if (pricetype == 2)
                    {
                        PriceDAL.DeleteByProductID(ID);
                        foreach (string price in pricess)
                        {
                            string[] pp = price.Split('&');
                            PriceInfo p = new PriceInfo()
                            {
                                ProductID = ID,
                                OPrice = DataConvert.ToDouble(pp[1]),
                                APrice = DataConvert.ToDouble(pp[2]),
                                Unit = pp[0],
                                SellCount = 0,
                                LibraryCount = DataConvert.ToInt(pp[3]),
                            };
                            PriceDAL.Save(p);
                        }
                    }

                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除产品
            hs.Add("Delete_Product", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[product]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*资讯分类*/
            #region 获取资讯分类
            hs.Add("Find_NewsType", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<NewsTypeInfo> list = NewsTypeDAL.FindPage(keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存资讯分类
            hs.Add("Save_NewsType", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //
                string name = JobRequest.GetRequestString("name"); //分类名称
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                NewsTypeInfo info = new NewsTypeInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Sort = sort
                };
                if (id == 0)
                {
                    ID = NewsTypeDAL.Save(info);
                }
                else
                {
                    ID = NewsTypeDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除资讯分类
            hs.Add("Delete_NewsType", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[newstype]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion


            /*留言反馈*/
            #region 获取留言反馈
            hs.Add("Find_Message", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<MessageInfo> list = MessageDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 删除留言反馈
            hs.Add("Delete_Message", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[message]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*产品标签*/
            #region 获取产品标签
            hs.Add("Find_Tags", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<TagsInfo> list = TagsDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存产品标签
            hs.Add("Save_Tags", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                string name = JobRequest.GetRequestString("name"); //名称
                int count = JobRequest.GetRequestInt("count"); //获取条数
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐到首页
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                TagsInfo info = new TagsInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Count = count,
                    Sort = sort
                };
                if (id == 0)
                {
                    ID = TagsDAL.Save(info);
                }
                else
                {
                    ID = TagsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除产品标签
            hs.Add("Delete_Tags", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[tags]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*活动*/
            #region 获取活动
            hs.Add("Find_Active", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<ActiveInfo> list = ActiveDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存活动
            hs.Add("Save_Active", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int productid = JobRequest.GetRequestInt("productid"); //产品ID
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); ; //活动图片
                int position = JobRequest.GetRequestInt("position"); //位置
                int isshow = JobRequest.GetRequestInt("isshow"); //是否显示
                int clickcount = JobRequest.GetRequestInt("clickcount"); //点击量
                DateTime createdate = JobRequest.GetRequestDateTime("createdate", DataConvert.DefaultDateTimeValue); //
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                ActiveInfo info = new ActiveInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    ProductID = productid,
                    Img = img,
                    Position = position,
                    IsShow = isshow,
                    ClickCount = clickcount,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = ActiveDAL.Save(info);
                }
                else
                {
                    ID = ActiveDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除活动
            hs.Add("Delete_Active", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[active]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*订单*/
            #region 获取订单
            hs.Add("Find_POrder", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int userid = JobRequest.GetRequestInt("userid"); //用户ID
                int state = JobRequest.GetRequestInt("state"); //订单状态
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<POrderInfo> list = POrderDAL.FindPage(adminid, -1, -1, begindate, enddate, page, Commons.PageSize, "", "", out count);
                if (list.Count > 0)
                {
                    List<POrderDetailInfo> childlist = POrderDetailDAL.FindListByOrderIDs(adminid, string.Join(",", list.Select(x => x.ID)));
                    foreach (POrderInfo info in list)
                    {
                        info.ChildList = childlist.Where(x => x.OrderID == info.ID).ToList();
                    }
                }
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 删除订单
            hs.Add("Delete_POrder", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[porder]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 发货
            hs.Add("Send_POrder", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //订单ID
                string logistics = JobRequest.GetRequestString("logistics"); //快递公司
                string expressnum = JobRequest.GetRequestString("expressnum"); //快递单号
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = POrderDAL.SendPOrder(adminid, id, logistics,expressnum);
                if (ok)
                {
                    return Commons.GetSuccess("收货成功", "");
                }
                else
                {
                    return Commons.GetFaild("收货失败");
                }
            });
            #endregion

            /*商品参数*/
            #region 获取商品参数
            hs.Add("Find_Param", (int adminid) =>
            {
                //参数
                int category1id = JobRequest.GetRequestInt("category1id"); //1级类别ID
                int category2id = JobRequest.GetRequestInt("category2id"); //2级类别ID
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                List<ParamInfo> list = ParamDAL.FindByCategory(adminid, category1id, category2id);
                foreach (ParamInfo info in list)
                {
                    if (info.Type == 1)
                    {
                        info.ChildList = list.Where(x => x.ParentID == info.ID).ToList();
                    }
                }
                return Commons.GetSuccess("获取成功", list);
            });
            #endregion
            #region 保存商品参数
            hs.Add("Save_Param", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int category1id = JobRequest.GetRequestInt("category1id"); //1级类别ID
                int category2id = JobRequest.GetRequestInt("category2id"); //2级类别ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //参数名称
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int type = JobRequest.GetRequestInt("type"); //参数类型 1.参数组  2.参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                ParamInfo info = new ParamInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Category1ID = category1id,
                    Category2ID = category2id,
                    ParentID = parentid,
                    Name = name,
                    Sort = sort,
                    Type = type
                };
                if (id == 0)
                {
                    ID = ParamDAL.Save(info);
                }
                else
                {
                    ID = ParamDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除商品参数
            hs.Add("Delete_Param", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[param]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*商品参数值*/
            #region 获取商品参数值
            hs.Add("Find_ProductParam", (int adminid) =>
            {
                //参数
                int productid = JobRequest.GetRequestInt("productid"); //商品ID
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                List<ProductParamInfo> list = ProductParamDAL.FindByProductID(adminid,productid);
                foreach (ProductParamInfo info in list)
                {
                    if (info.Type == 1)
                    {
                        info.ChildList = list.Where(x => x.ParentID == info.ID).ToList();
                    }
                }
                return Commons.GetSuccess("获取成功", list);
            });
            #endregion
            #region 保存商品参数值
            hs.Add("Save_ProductParam", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int productid = JobRequest.GetRequestInt("productid"); //商品ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //参数名称
                string value = JobRequest.GetRequestString("value"); //参数值
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int type = JobRequest.GetRequestInt("type"); //1.参数组  2.参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                ProductParamInfo info = new ProductParamInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    ProductID = productid,
                    ParentID = parentid,
                    Name = name,
                    Value = value,
                    Sort = sort,
                    Type = type
                };
                if (id == 0)
                {
                    ID = ProductParamDAL.Save(info);
                }
                else
                {
                    ID = ProductParamDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除商品参数值
            hs.Add("Delete_ProductParam", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[productparam]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 修改商品参数值
            hs.Add("Update_ProductParamName", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //参数名称
                //参数
                bool ok = ProductParamDAL.UpdateProductParamName(adminid, id, name);
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion

            /*优惠券*/
            #region 获取优惠券
            hs.Add("Find_Quan", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<QuanInfo> list = QuanDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存优惠券
            hs.Add("Save_Quan", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                float money = JobRequest.GetRequestFloat("money"); //金额
                float man = JobRequest.GetRequestFloat("man"); //满减额度
                int isshow = JobRequest.GetRequestInt("isshow"); //是否可用
                DateTime begindate = JobRequest.GetRequestDateTime("begindate", DataConvert.DefaultDateTimeValue); //开始时间
                DateTime enddate = JobRequest.GetRequestDateTime("enddate", DataConvert.DefaultDateTimeValue); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                QuanInfo info = new QuanInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Money = money,
                    Man = man,
                    IsShow = isshow,
                    BeginDate = begindate,
                    EndDate = enddate,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = QuanDAL.Save(info);
                }
                else
                {
                    ID = QuanDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除优惠券
            hs.Add("Delete_Quan", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[quan]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*菜单*/
            #region 获取菜单
            hs.Add("Find_Menu", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<MenuInfo> alllist = MenuDAL.FindAll();
                List<MenuInfo> parentlist = alllist.Where(x => x.ParentID == 0).ToList();
                List<MenuInfo> list = new List<MenuInfo>();
                foreach (MenuInfo menu in parentlist)
                {
                    list.Add(menu);
                    list.AddRange(alllist.Where(x => x.ParentID == menu.ID));
                }
                return Commons.GetSuccess("获取成功", list, list.Count);
            });
            #endregion
            #region 保存菜单
            hs.Add("Save_Menu", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //菜单名称
                string path = JobRequest.GetRequestString("path"); //菜单路径
                string btns = JobRequest.GetRequestString("btns"); //按钮
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int isshow = JobRequest.GetRequestInt("isshow"); //是否显示
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                MenuInfo info = new MenuInfo()
                {
                    ID = id,
                    ParentID = parentid,
                    Name = name,
                    Path = path,
                    Btns = btns,
                    Sort = sort,
                    IsShow = isshow
                };
                if (id == 0)
                {
                    ID = MenuDAL.Save(info);
                }
                else
                {
                    ID = MenuDAL.Update(info);
                }
                if (ID > 0)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除菜单
            hs.Add("Delete_Menu", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[menu]");
                if (ok)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*按钮*/
            #region 获取按钮
            hs.Add("Find_Btns", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<BtnsInfo> list = BtnsDAL.FindAll();
                dynamic obj = new ExpandoObject();
                obj.list = list;
                obj.count = count;
                return Commons.GetSuccess("获取成功", obj);
            });
            #endregion
            #region 保存按钮
            hs.Add("Save_Btns", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //按钮名称
                string method = JobRequest.GetRequestString("method"); //按钮方法
                int sort = JobRequest.GetRequestInt("sort"); //排序
                string color = JobRequest.GetRequestString("color"); //按钮颜色
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                BtnsInfo info = new BtnsInfo()
                {
                    ID = id,
                    Name = name,
                    Method = method,
                    Sort = sort,
                    Color = color
                };
                if (id == 0)
                {
                    ID = BtnsDAL.Save(info);
                }
                else
                {

                    ID = BtnsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除按钮
            hs.Add("Delete_Btns", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[btns]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*修改配置信息*/
            
            #region 修改公司介绍
            hs.Add("Update_Introduce", (int adminid) =>
            {
                //参数
                string introduce = JobRequest.GetRequestString("introduce"); //公司介绍
                //参数
                bool ok = CommonDAL.UpdateColumnByID(adminid, "Introduce", introduce, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 修改企业文化
            hs.Add("Update_Culture", (int adminid) =>
            {
                //参数
                string culture = JobRequest.GetRequestString("culture"); //企业文化
                //参数
                bool ok = CommonDAL.UpdateColumnByID(adminid, "Culture", culture, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 修改版权信息
            hs.Add("Update_Copyright", (int adminid) =>
            {
                //参数
                string copyright1 = JobRequest.GetRequestString("copyright1"); //
                string copyright2 = JobRequest.GetRequestString("copyright2"); //
                string copyright3 = JobRequest.GetRequestString("copyright3"); //
                string copyright4 = JobRequest.GetRequestString("copyright4"); //
                string copyright5 = JobRequest.GetRequestString("copyright5"); //
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = adminid,
                    Copyright1 = copyright1.Replace(" ", "&nbsp;"),
                    Copyright2 = copyright2.Replace(" ", "&nbsp;"),
                    Copyright3 = copyright3.Replace(" ", "&nbsp;"),
                    Copyright4 = copyright4.Replace(" ", "&nbsp;"),
                    Copyright5 = copyright5.Replace(" ", "&nbsp;"),
                };
                ID = AdminDAL.UpdateCopyright(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 修改版权信息
            hs.Add("Update_Config", (int adminid) =>
            {
                //参数
                string appid = JobRequest.GetRequestString("appid"); //appid
                string appsecret = JobRequest.GetRequestString("appsecret"); //appsecret
                string mchid = JobRequest.GetRequestString("mchid"); //商户号
                string appkey = JobRequest.GetRequestString("appkey"); //支付秘钥
                double score = JobRequest.GetRequestDouble("score"); //积分
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = adminid,
                    Score = score,
                    AppId=appid,
                    AppSecret=appsecret,
                    MchId=mchid,
                    AppKey=appkey
                };
                ID = AdminDAL.UpdateConfig(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            
            #region 修改排序
            hs.Add("ReSort", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                string table = JobRequest.GetRequestString("table"); //表
                //参数
                bool ok = CommonDAL.ReSort(id,sort,table);
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改导航菜单
            hs.Add("Update_Menu", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                string path = JobRequest.GetRequestString("path"); //路径
                string icon = JobRequest.GetRequestString("icon"); //图标
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + name + "&" + icon + "&" + path, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改MenuTags标签
            hs.Add("Update_MenuTags", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int menusort = JobRequest.GetRequestInt("menusort"); //顺序
                int menuistop = JobRequest.GetRequestInt("menuistop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int tagsid = JobRequest.GetRequestInt("tagsid"); //标签ID
                string menuicon = JobRequest.GetRequestString("menuicon"); //图标
                //参数
                int ID = 0;
                TagsInfo info = new TagsInfo()
                {
                    ID = tagsid,
                    Name = name,
                    MenuIcon = menuicon,
                    MenuSort = menusort,
                    MenuIsTop = menuistop
                };
                ID = TagsDAL.Edit(info);

                if (ID>0)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改MenuCategory菜单
            hs.Add("Update_MenuCategory", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int menusort = JobRequest.GetRequestInt("menusort"); //顺序
                int menuistop = JobRequest.GetRequestInt("menuistop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int categoryid = JobRequest.GetRequestInt("categoryid"); //分类ID
                string menuicon = JobRequest.GetRequestString("menuicon"); //图标
                //参数
                int ID = 0;
                CategoryInfo info = new CategoryInfo()
                {
                    ID = categoryid,
                    Name = name,
                    MenuIcon = menuicon,
                    MenuSort = menusort,
                    MenuIsTop = menuistop
                };
                ID = CategoryDAL.Edit(info);

                if (ID > 0)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改商城公告
            hs.Add("Update_News", (int adminid) =>
            {
                //参数
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int count = JobRequest.GetRequestInt("count"); //数量
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, "News", sort + "&" + istop + "&" + count + "&" + name, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改优惠券
            hs.Add("Update_Quan", (int adminid) =>
            {
                //参数
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int count = JobRequest.GetRequestInt("count"); //数量
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, "Quan", sort + "&" + istop + "&" + count + "&" + name, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改活动专区
            hs.Add("Update_Active", (int adminid) =>
            {
                //参数
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int count = JobRequest.GetRequestInt("count"); //数量
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, "Active", sort + "&" + istop + "&" + count + "&" + name, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改ModuleTags标签
            hs.Add("Update_ModuleTags", (int adminid) =>
            {
                //参数
                int modulesort = JobRequest.GetRequestInt("modulesort"); //顺序
                int moduleistop = JobRequest.GetRequestInt("moduleistop"); //是否推荐
                int count = JobRequest.GetRequestInt("count"); //数量
                string name = JobRequest.GetRequestString("name"); //名字
                int tagsid = JobRequest.GetRequestInt("tagsid"); //标签ID
                //参数
                int ID = 0;
                TagsInfo info = new TagsInfo()
                {
                    ID = tagsid,
                    Name = name,
                    ModuleSort = modulesort,
                    ModuleIsTop = moduleistop,
                    Count = count
                };
                ID = TagsDAL.Modify(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改ModuleCategory菜单
            hs.Add("Update_ModuleCategory", (int adminid) =>
            {
                //参数
                int modulesort = JobRequest.GetRequestInt("modulesort"); //顺序
                int moduleistop = JobRequest.GetRequestInt("moduleistop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int categoryid = JobRequest.GetRequestInt("categoryid"); //分类ID
                int count = JobRequest.GetRequestInt("count"); //数量
                //参数
                int ID = 0;
                CategoryInfo info = new CategoryInfo()
                {
                    ID = categoryid,
                    Name = name,
                    ModuleSort = modulesort,
                    ModuleIsTop = moduleistop,
                    Count = count
                };
                ID = CategoryDAL.Modify(info);

                if (ID > 0)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改热门关键词
            hs.Add("Update_Hot", (int adminid) =>
            {
                //参数
                string hot = JobRequest.GetRequestString("hot"); //热门关键词
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, "Hot", hot, "[admin]");
                if (ok)
                {
                    B.MyAdmin.Hot = hot;
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}